/*
    Copyright (C) 2010 jungil Han <jungil.Han@gmail.com>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef FILEREADER_H
#define FILEREADER_H

#include <QtCore/QThread>
#include <QtCore/QList>

class FileReader : public QThread
{
    Q_OBJECT

signals:
    void readStarted(QWidget*);
    void readFinished(QWidget*, QString*);
    void readProgress(QWidget*, QString*, int);
    void codecDected(QString);
    void fileSizeNotify(QWidget*, long);
    void fileNameNotify(QWidget*, QString);
    void finished(QWidget*);

public:
    FileReader(QWidget* requester, const QString& codec, QObject* parent = 0);
    virtual ~FileReader();

    void start(const QString& fileName);
    void suspend();

protected:
    virtual void run();

private slots:
    void finished();

private:
    void clearList();
    void parse(const QString& sentence, int line);

private:
    QWidget* m_requester;
    QString m_fileName;
    QString m_codec;
    volatile bool m_isRunning;
    QList<QString*> m_byteArrayList;
};

#endif // FILEREADER_H
